import 'package:bruno/bruno.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:getwidget/getwidget.dart';
import 'package:meal/constant/sizes.dart';
import 'package:meal/route/route.dart';
import 'package:meal/utils/colors.dart';
import 'package:meal/utils/styles.dart';
import 'package:meal/utils/tools.dart';

///
/// 店铺管理
///
class StoreManage extends StatefulWidget {
  const StoreManage({Key? key}) : super(key: key);

  @override
  State<StoreManage> createState() => _StoreManageState();
}

class _StoreManageState extends State<StoreManage> with SingleTickerProviderStateMixin {
  /// 是否平台
  bool isPlatform = true;

  /// 是否开发票
  bool isInvoice = true;

  /// 自行配送
  bool auto = true;

  late final Offset begin = Offset.zero;

  /// 第一 结束位置移出右侧屏幕
  late final Offset end1 = const Offset(-1.0, 0.0);

  /// 第二 初始位置在左侧屏幕
  late final Offset begin2 = const Offset(1.0, 0.0);

  late final Tween<Offset> tween1 = Tween(begin: begin, end: end1);
  late final Tween<Offset> tween2 = Tween(begin: begin2, end: begin);

  late final AnimationController _controller =
      AnimationController(duration: const Duration(seconds: 1), vsync: this);

  /// 使用自定义曲线动画过渡效果
  late final Animation<Offset> _animation1 = tween1.animate(
    CurvedAnimation(
      parent: _controller,
      curve: Curves.easeInOut,
    ),
  );

  late final Animation<Offset> _animation2 = tween2.animate(CurvedAnimation(
    parent: _controller,
    curve: Curves.easeInOut,
  ));

  double get leftWidth {
    return Sizes.default90;
  }

  double get rowHeight {
    return Sizes.default60;
  }

  BoxDecoration changeBoxDecoration([bool isActive = true]) {
    if (isActive) {
      return BoxDecoration(
          color: ColorsUtils.rgba(255, 238, 238, 1),
          borderRadius: BorderRadius.circular(Sizes.default15),
          border: Border.all(color: ColorsUtils.rgba(255, 110, 83, 1)));
    }
    return BoxDecoration(
      color: ColorsUtils.rgba(245, 245, 245, 1),
      borderRadius: BorderRadius.circular(Sizes.default15),
    );
  }

  @override
  void initState() {
    _controller.reverse();
    super.initState();
  }

  @override
  void dispose() {
    _controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: ToolsUtils.getDefaultBackgroundColor(),
      appBar: ToolsUtils.getDefaultBrnAppBar('店铺管理'),
      body: SingleChildScrollView(
        child: Column(
          children: [
            Container(
              height: Sizes.default50,
              alignment: Alignment.centerLeft,
              padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
              child: Text('堂食营业',
                  style: StylesUtils.customTextStyle(
                      color: ColorsUtils.color797, fontSize: Sizes.default13)),
            ),
            Container(
              padding:
                  const EdgeInsets.symmetric(vertical: Sizes.default8, horizontal: Sizes.default15),
              decoration: const BoxDecoration(
                color: Colors.white,
              ),
              child: Column(
                children: [
                  Container(
                    height: rowHeight,
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                    child: Row(
                      children: [
                        Container(
                          width: leftWidth,
                          alignment: Alignment.centerLeft,
                          child: Text(
                            '预订手机号',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                          ),
                        ),
                        Expanded(
                            child: Container(
                          decoration: BoxDecoration(
                              color: ColorsUtils.rgba(247, 247, 247, 1),
                              borderRadius: BorderRadius.circular(Sizes.default10)),
                          alignment: Alignment.centerLeft,
                          padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
                          child: Wrap(
                            spacing: Sizes.default8,
                            alignment: WrapAlignment.start,
                            crossAxisAlignment: WrapCrossAlignment.center,
                            children: [
                              Text('+86',
                                  style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                              Text('1355897560',
                                  style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                            ],
                          ),
                        ))
                      ],
                    ),
                  ),
                  Container(
                      height: rowHeight,
                      padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                      child: GestureDetector(
                        onTap: () {
                          Get.toNamed(RouteGet.userStoreBizTime);
                        },
                        child: Row(
                          children: [
                            Container(
                              width: leftWidth,
                              alignment: Alignment.centerLeft,
                              child: Text(
                                '营业时段',
                                style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                              ),
                            ),
                            Expanded(
                                child: Container(
                              padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
                              decoration: BoxDecoration(
                                  color: ColorsUtils.rgba(247, 247, 247, 1),
                                  borderRadius: BorderRadius.circular(Sizes.default10)),
                              alignment: Alignment.centerLeft,
                              child: Row(
                                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                children: [
                                  Text('11:30-13:30, 17:30-19:30',
                                      style:
                                          StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                                  BrunoTools.getAssetSizeImage(BrnAsset.iconRightArrow, 16, 16)
                                ],
                              ),
                            ))
                          ],
                        ),
                      )),
                ],
              ),
            ),
            Container(
              height: Sizes.default50,
              alignment: Alignment.centerLeft,
              padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
              child: Text('外卖营业',
                  style: StylesUtils.customTextStyle(
                      color: ColorsUtils.color797, fontSize: Sizes.default13)),
            ),
            Container(
              padding:
                  const EdgeInsets.symmetric(vertical: Sizes.default8, horizontal: Sizes.default15),
              decoration: const BoxDecoration(
                color: Colors.white,
              ),
              child: Column(
                children: [
                  Container(
                    height: rowHeight,
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                    child: InkWell(
                      onTap: () {
                        Get.toNamed(RouteGet.userStoreMobile);
                      },
                      child: Row(
                        children: [
                          Container(
                            width: leftWidth,
                            alignment: Alignment.centerLeft,
                            child: Text(
                              '接单手机号',
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                            ),
                          ),
                          Expanded(
                              child: Container(
                                decoration: BoxDecoration(
                                    color: ColorsUtils.rgba(247, 247, 247, 1),
                                    borderRadius: BorderRadius.circular(Sizes.default10)),
                                alignment: Alignment.centerLeft,
                                padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text.rich(TextSpan(children: [
                                      TextSpan(
                                          text: '+86',
                                          style:
                                          StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                                      TextSpan(
                                          text: '1355897560',
                                          style:
                                          StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                                    ])),
                                    BrunoTools.getAssetSizeImage(BrnAsset.iconRightArrow, 16, 16)
                                  ],
                                ),
                              ))
                        ],
                      ),
                    )
                  ),
                  Container(
                    height: rowHeight,
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                    child: InkWell(
                      onTap: () {
                        Get.toNamed(RouteGet.userStoreBizTime);
                      },
                      child: Row(
                        children: [
                          Container(
                            width: leftWidth,
                            alignment: Alignment.centerLeft,
                            child: Text(
                              '营业时段',
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                            ),
                          ),
                          Expanded(
                              child: Container(
                                padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
                                decoration: BoxDecoration(
                                    color: ColorsUtils.rgba(247, 247, 247, 1),
                                    borderRadius: BorderRadius.circular(Sizes.default10)),
                                alignment: Alignment.centerLeft,
                                child: Row(
                                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                  children: [
                                    Text('11:30-13:30, 17:30-19:30',
                                        style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                                    BrunoTools.getAssetSizeImage(BrnAsset.iconRightArrow, 16, 16)
                                  ],
                                ),
                              ))
                        ],
                      ),
                    ),
                  ),
                  Container(
                    height: rowHeight,
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                    child: Row(
                      children: [
                        Container(
                          width: leftWidth,
                          alignment: Alignment.centerLeft,
                          child: Text(
                            '起步价',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                          ),
                        ),
                        Expanded(
                            child: Container(
                          decoration: BoxDecoration(
                              color: ColorsUtils.rgba(247, 247, 247, 1),
                              borderRadius: BorderRadius.circular(Sizes.default10)),
                          alignment: Alignment.centerLeft,
                          padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
                          child: Text('￥150',
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                        ))
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Container(
              height: Sizes.default50,
              alignment: Alignment.centerLeft,
              padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
              child: Text('外卖配送',
                  style: StylesUtils.customTextStyle(
                      color: ColorsUtils.color797, fontSize: Sizes.default13)),
            ),
            Container(
              padding:
                  const EdgeInsets.symmetric(vertical: Sizes.default8, horizontal: Sizes.default15),
              decoration: const BoxDecoration(
                color: Colors.white,
              ),
              child: Column(
                children: [
                  Container(
                    height: rowHeight,
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                    child: Row(
                      children: [
                        Container(
                          width: leftWidth,
                          alignment: Alignment.centerLeft,
                          child: Text(
                            '配送方式',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color333),
                          ),
                        ),
                        Expanded(
                            child: Container(
                          alignment: Alignment.centerLeft,
                          padding: const EdgeInsets.only(left: Sizes.default15),
                          child: Wrap(
                            spacing: Sizes.default15,
                            alignment: WrapAlignment.start,
                            crossAxisAlignment: WrapCrossAlignment.center,
                            children: [
                              InkWell(
                                onTap: () {
                                  setState(() {
                                    isPlatform = true;
                                    _controller.reverse();
                                  });
                                },
                                child: Container(
                                  alignment: Alignment.center,
                                  constraints: const BoxConstraints.expand(
                                      width: 100, height: Sizes.default30),
                                  decoration: changeBoxDecoration(isPlatform),
                                  child: Text(
                                    '平台配送',
                                    style: isPlatform
                                        ? StylesUtils.customTextStyle(color: ColorsUtils.colorFf6)
                                        : StylesUtils.customTextStyle(color: ColorsUtils.color333),
                                  ),
                                ),
                              ),
                              InkWell(
                                onTap: () {
                                  setState(() {
                                    isPlatform = false;
                                    _controller.forward();
                                  });
                                },
                                child: Container(
                                  alignment: Alignment.center,
                                  constraints: const BoxConstraints.expand(
                                      width: 100, height: Sizes.default30),
                                  decoration: changeBoxDecoration(!isPlatform),
                                  child: Text('商家配送',
                                      style: !isPlatform
                                          ? StylesUtils.customTextStyle(color: ColorsUtils.colorFf6)
                                          : StylesUtils.customTextStyle(
                                              color: ColorsUtils.color333)),
                                ),
                              ),
                            ],
                          ),
                        ))
                      ],
                    ),
                  ),
                  Container(
                    height: rowHeight,
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('基础距离',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                        Text('2 km',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color797))
                      ],
                    ),
                  ),
                  Container(
                    height: rowHeight,
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('基础配送费',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                        Text('￥ 15',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color797))
                      ],
                    ),
                  ),
                  Container(
                    height: rowHeight,
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('每百米计费',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                        Text('￥ 2', style: StylesUtils.customTextStyle(color: ColorsUtils.color797))
                      ],
                    ),
                  ),
                  Container(
                    alignment: Alignment.centerLeft,
                    padding: const EdgeInsets.only(bottom: Sizes.default10),
                    child: Text(
                      '超出基础距离到最远距离的配送费',
                      style: StylesUtils.customTextStyle(
                          color: ColorsUtils.color999, fontSize: Sizes.default12),
                    ),
                  ),
                  Container(
                    height: rowHeight,
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('最远配送距离',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                        Text('10 km',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color797))
                      ],
                    ),
                  ),
                  Container(
                    height: rowHeight,
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('0-3点加价',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                        Text('10￥/单',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color797))
                      ],
                    ),
                  ),
                  Container(
                    height: rowHeight,
                    padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text('3-6点加价',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                        Text('15￥/单',
                            style: StylesUtils.customTextStyle(color: ColorsUtils.color797))
                      ],
                    ),
                  ),
                ],
              ),
            ),
            Stack(
              children: [
                SlideTransition(
                  position: _animation1,
                  child: Column(
                    children: [
                      Container(
                        height: Sizes.default50,
                        alignment: Alignment.centerLeft,
                        padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
                        child: Text('自行配送',
                            style: StylesUtils.customTextStyle(
                                color: ColorsUtils.color797, fontSize: Sizes.default13)),
                      ),
                      Container(
                          padding: const EdgeInsets.symmetric(
                              vertical: Sizes.default8, horizontal: Sizes.default15),
                          decoration: const BoxDecoration(
                            color: Colors.white,
                          ),
                          child: Column(
                            children: [
                              Container(
                                height: rowHeight,
                                padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                                child: Row(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Expanded(
                                        child: Container(
                                      alignment: Alignment.centerLeft,
                                      padding: const EdgeInsets.only(right: Sizes.default10),
                                      child: Column(
                                        children: [
                                          Container(
                                            alignment: Alignment.centerLeft,
                                            child: Text('是否自行配送',
                                                style: StylesUtils.customTextStyle(
                                                    color: ColorsUtils.color333)),
                                          ),
                                          Container(
                                            alignment: Alignment.centerLeft,
                                            margin: const EdgeInsets.only(top: Sizes.default5),
                                            child: Text('平台无人接单配送时商家可自行配送',
                                                style: StylesUtils.customTextStyle(
                                                    fontSize: Sizes.default12,
                                                    color: ColorsUtils.color999)),
                                          )
                                        ],
                                      ),
                                    )),
                                    GFToggle(
                                      onChanged: (bool? val) {
                                        setState(() {
                                          auto = val!;
                                        });
                                      },
                                      value: auto,
                                      type: GFToggleType.ios,
                                      boxShape: BoxShape.circle,
                                      enabledTrackColor: ColorsUtils.rgba(255, 110, 83, 1),
                                      enabledThumbColor: Colors.white,
                                    )
                                  ],
                                ),
                              ),
                              Container(
                                height: rowHeight,
                                padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                                child: InkWell(
                                  onTap: () {
                                    Get.toNamed(RouteGet.userStoreDeliveryPeriod);
                                  },
                                  child: Row(
                                    children: [
                                      Container(
                                        width: leftWidth,
                                        alignment: Alignment.centerLeft,
                                        child: Text(
                                          '配送时段',
                                          style: StylesUtils.customTextStyle(
                                              color: ColorsUtils.color333),
                                        ),
                                      ),
                                      Expanded(
                                          child: Container(
                                            padding:
                                            const EdgeInsets.symmetric(horizontal: Sizes.default15),
                                            decoration: BoxDecoration(
                                                color: ColorsUtils.rgba(247, 247, 247, 1),
                                                borderRadius: BorderRadius.circular(Sizes.default10)),
                                            alignment: Alignment.centerLeft,
                                            child: Row(
                                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                                              children: [
                                                Text('同外卖营业时段',
                                                    style: StylesUtils.customTextStyle(
                                                        color: ColorsUtils.color333)),
                                                BrunoTools.getAssetSizeImage(
                                                    BrnAsset.iconRightArrow, 16, 16)
                                              ],
                                            ),
                                          ))
                                    ],
                                  ),
                                ),
                              ),
                              Container(
                                height: rowHeight,
                                padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
                                child: Row(
                                  children: [
                                    Container(
                                      width: leftWidth,
                                      alignment: Alignment.centerLeft,
                                      child: Text(
                                        '最远配送距离',
                                        style: StylesUtils.customTextStyle(
                                            color: ColorsUtils.color333),
                                      ),
                                    ),
                                    Expanded(
                                        child: Container(
                                      padding:
                                          const EdgeInsets.symmetric(horizontal: Sizes.default15),
                                      margin: const EdgeInsets.only(right: Sizes.default10),
                                      decoration: BoxDecoration(
                                          color: ColorsUtils.rgba(247, 247, 247, 1),
                                          borderRadius: BorderRadius.circular(Sizes.default10)),
                                      alignment: Alignment.centerLeft,
                                      child: Text('5',
                                          style: StylesUtils.customTextStyle(
                                              color: ColorsUtils.color333)),
                                    )),
                                    Container(
                                      alignment: Alignment.centerRight,
                                      child: Text('km',
                                          style: StylesUtils.customTextStyle(
                                              color: ColorsUtils.color333)),
                                    )
                                  ],
                                ),
                              ),
                            ],
                          ))
                    ],
                  ),
                ),
                SlideTransition(
                  position: _animation2,
                  child: Container(
                    height: Sizes.default50,
                    alignment: Alignment.centerLeft,
                    padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
                    child: Text('✻ 每百米计费是指超出基础距离到最远距离的配送费',
                        style: StylesUtils.customTextStyle(
                            color: ColorsUtils.color797, fontSize: Sizes.default13)),
                  ),
                ),
              ],
            ),
            Container(
              height: Sizes.default50,
              alignment: Alignment.centerLeft,
              padding: const EdgeInsets.symmetric(horizontal: Sizes.default15),
              child: Text('线上开票',
                  style: StylesUtils.customTextStyle(
                      color: ColorsUtils.color797, fontSize: Sizes.default13)),
            ),
            Container(
              padding:
                  const EdgeInsets.symmetric(vertical: Sizes.default8, horizontal: Sizes.default15),
              decoration: const BoxDecoration(
                color: Colors.white,
              ),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Expanded(
                      child: Container(
                    alignment: Alignment.centerLeft,
                    padding: const EdgeInsets.only(right: Sizes.default10),
                    child: Column(
                      children: [
                        Container(
                          alignment: Alignment.centerLeft,
                          child: Text('是否支持线上开具发票',
                              style: StylesUtils.customTextStyle(color: ColorsUtils.color333)),
                        ),
                        Container(
                          alignment: Alignment.centerLeft,
                          margin: const EdgeInsets.only(top: Sizes.default5),
                          child: Text('开具发票内容为"餐饮服务"的纸质发票',
                              style: StylesUtils.customTextStyle(
                                  fontSize: Sizes.default12, color: ColorsUtils.color999)),
                        )
                      ],
                    ),
                  )),
                  GFToggle(
                    onChanged: (bool? val) {
                      setState(() {
                        isInvoice = val!;
                      });
                    },
                    value: isInvoice,
                    type: GFToggleType.ios,
                    boxShape: BoxShape.circle,
                    enabledTrackColor: ColorsUtils.rgba(255, 110, 83, 1),
                    enabledThumbColor: Colors.white,
                  )
                ],
              ),
            )
          ],
        ),
      ),
      bottomNavigationBar: SafeArea(
        top: false,
        child: Container(
            height: Sizes.default60,
            alignment: Alignment.topCenter,
            padding: const EdgeInsets.symmetric(vertical: Sizes.default10),
            decoration: const BoxDecoration(color: Colors.white),
            child: SizedBox(
              height: Sizes.default40,
              child: FractionallySizedBox(
                widthFactor: 0.9,
                child: GFButton(
                    onPressed: () {},
                    text: '确定',
                    textStyle: StylesUtils.customTextStyle(fontSize: Sizes.default16),
                    shape: GFButtonShape.pills,
                    type: GFButtonType.solid,
                    size: GFSize.LARGE,
                    color: ColorsUtils.parseColorFromHexString(ColorsUtils.colorFf6)),
              ),
            )),
      ),
    );
  }
}
